package com.aduerr.v1shouyin.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class TextUtils {
    public static String removeTrim(String str) {
        if(str.indexOf(".") > 0) {
            str = str.replaceAll("0+?$", "");
            str = str.replaceAll("[.]$", "");
        }
        return str;

    }


    public static String formatTosepara(String data) {
        String dataChange = data.substring(0, data.length() - 3);
        DecimalFormat df = new DecimalFormat("#,###");
        if(dataChange.length() > 4) {
            return df.format(Integer.parseInt(dataChange));
        } else {
            return dataChange;
        }
    }

    public static String formatToseparatow(String data) {
        if(data.length() > 0) {
            Double dataChange = Double.parseDouble(data);
            if(dataChange < 100) {
                return data;
            } else {
                DecimalFormat df = new DecimalFormat("#,###.00");
                return df.format(dataChange);
            }
        }
        return data;
    }

    public static String formatTosepaa(String data) {

        DecimalFormat df = new DecimalFormat("#,###.00");
        return df.format(Double.parseDouble(data));

    }


    public static String getLastThree(String data) {
        return data.substring(data.length() - 3, data.length());
    }

    //判断是否大于5位数
    public static String changeToWan(String data) {
        if(Double.parseDouble(data) >= 10000) {
            double value = new BigDecimal(Double.parseDouble(data) / 10000).setScale(2,
                    BigDecimal.ROUND_HALF_UP).doubleValue();
            return String.valueOf(value) + "万元";
        } else {
            return data;
        }
    }

    public static String changToWantwo(String data) {
        if(data.length() > 5) {
            return data.substring(0, data.length() - 4) + "万";
        } else {
            return data;
        }
    }

    public static String caveTwo(String data) {
        Double cny = Double.parseDouble(data);//转换成Double
        DecimalFormat df = new DecimalFormat("0.00");//格式化
        String CNY = df.format(cny);
        return CNY;
    }

}
